package sein.android.hopenote;

import java.util.ArrayList;

import android.R.string;
import android.app.ActivityGroup;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import sein.android.hopenote.Note_Add;

public class Note_Input_Tab extends ActivityGroup {
	public static Note_Input_Tab InputTabGroup;
	private ArrayList<View> history;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		history = new ArrayList<View>();		
		InputTabGroup = this;
		
		Intent intent = new Intent(Note_Input_Tab.this,Note_Input.class);
		View view = getLocalActivityManager().startActivity("Note_input", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		
		replaceView(view,"note_input");
		//replaceView(view,"note_add");
	}
	
	// 새로운 Level의 Activity를 추가하는 경우
	 public void replaceView(View view,String pageid) {
		 history.add(view);
		 Log.d("test", getParent().toString());
		 View viewToload = null;
		 
		 if (pageid.equals("note_add")){
			 viewToload =  LayoutInflater.from(getParent()).inflate(getResources().getIdentifier(pageid, "layout", getPackageName()),null);
			Note_Add note_add = new Note_Add();
			note_add.Setting(getApplicationContext(),viewToload);
		 }
		 else {
			 
			 viewToload = view;
		 }
		  	 
		 
		 
		 
		 //View viewToload = LayoutInflater.from(this).inflate(view.getId(),null);
		 setContentView(viewToload);
	 }
		 
	 // Back Key가 눌러졌을 경우에 대한 처리
	 public void back() {
	  if(history.size() > 0) {
	   history.remove(history.size()-1);
	   if(history.size() ==  0)
	    finish();
	   else 
	   {
		   setContentView(history.get(history.size()-1));
	   }
	  } 
	  else
	  {
	   finish();
	  }
	 }
		 
		 // Back Key에 대한 Event Handler
	 @Override
	 public void onBackPressed() {
		 InputTabGroup.back();
	  return ;
	 }

	
}
